import cocos, pyglet
from cocos.director import director
from cocos.sprite import *
from pyglet.gl import *


class ImageLayer(cocos.layer.Layer):
    """Show a centered image"""
    def __init__(self, imagename):
        super(ImageLayer, self).__init__()
        w,h = director.get_window_size()
        self.add(Sprite(imagename, position=(w/2,h/2)))

class BGScreenLayer(cocos.layer.Layer):
    def __init__(self):
        super(BGScreenLayer, self).__init__()
        self.w, self.h = director.window.width, director.window.height
        texture = pyglet.image.Texture.create_for_size(GL_TEXTURE_2D, self.w, self.h, GL_RGBA)
        texture.blit_into(pyglet.image.get_buffer_manager().get_color_buffer(), 0,0,0)
        self.bg = texture.get_region(0, 0, self.w, self.h)
        
        self.add(cocos.layer.ColorLayer(0,0,0,100))
        
    def draw(self):
        self.bg.blit(0, 0, width=self.w, height=self.h)
        super(BGScreenLayer, self).draw()